fix: drop down close issue of multiselect component #1265
Closed
+18
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes (including videos or screenshots)
I've created a handleOnMouseDown function to control the visibility of the dropdown menu.
In the Anchor component, the onClick prop has been assigned an empty function since it's already being managed by the handleMouseDown function provided as a prop on the Box component. Additionally, a custom function called handleBlur has been introduced and is now assigned to the onBlur prop of the anchor component. This function is responsible for hiding the dropdown only when necessary. The handleClick function has also been modified to only work in creating focus within the box.
The sequence of actions is as follows: onMouseDown first, followed by onBlur, and finally onClick.
2024-01-16.22-50-44.mp4
Issue(s)
Closes #1305
Further comments
The issue occurred because the onBlur event, responsible for hiding the dropdown when clicking outside, executed before the onClick event. Therefore, clicking inside the box, such as on the arrow icon, triggered the onBlur event to hide the dropdown, and then the onClick event mistakenly thought it was hidden and displayed it again. To address this, I employed the onMouseDown event to better manage these scenarios.